﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace Lead2012.Business
{
    public class ReportBaseColumnRepository
    {
        // Create an instance of entity
        Lead2012Entities entities = new Lead2012Entities();
        
        public ReportBaseColumn GetSingle(int baseId, int fieldId)
        {
            return (from _object in entities.ReportBaseColumns where _object.BaseId == baseId && _object.FieldId == fieldId select _object).FirstOrDefault();
        }

        public void Create(ReportBaseColumn _object)
        {
            entities.AddToReportBaseColumns(_object);
            entities.SaveChanges();
        }

        public void Update(ReportBaseColumn _object)
        {
            entities.SaveChanges();
        }
        public void Delete(int baseId, int fieldId)
        {
            var _object = (from _list in entities.ReportBaseColumns where _list.BaseId == baseId && _list.FieldId == fieldId select _list).First();
            entities.DeleteObject(_object);
            entities.SaveChanges();
        }
        public void Save(ReportBaseColumn _object)
        {
            _object.EntityKey = (from ReportBaseColumn ac in entities.ReportBaseColumns where ac.BaseId == _object.BaseId && ac.FieldId == _object.FieldId select ac).FirstOrDefault().EntityKey;
            entities.SaveChanges();
        }
    }
}